#!/usr/bin/python
# coding=utf-8
# Filename: server.py

import web
import function

urls = (
    "/ping", "ping",
    "/move", "move",
    "/(.*)", "what"
    )


class ping:
    def GET(self):
        return "ok"


class move:
    def GET(self):
        query_data = web.input()
        if query_data.direction == "1":
            function.turn(1)
            return "Go up"
        elif query_data.direction == "2":
            function.turn(2)
            return "Go right"
        elif query_data.direction == "3":
            function.turn(3)
            return "Go down"
        elif query_data.direction == "4":
            function.turn(4)
            return "Go left"
        else:
            return "Error"


class what:
    def GET(self, name_url):
        i = web.input(name="World")

        if not name_url:
            name_url = "World"

        return "Hello, " + name_url + " & " + i.name + "!"


if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()
